package org.finesys.common.dataPermission.dept.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.finesys.common.core.exception.BusinessException;
import org.finesys.common.core.module.DeptDataPermissionEntity;
import org.finesys.common.core.module.ROpt;
import org.finesys.common.security.core.module.AuthUser;
import org.finesys.system.api.service.RoleService;

@Slf4j
@RequiredArgsConstructor
public class DataPermissionService {

    private final RoleService roleService;

    /**
     * 获得登陆用户的部门数据权限
     *
     * @param authUser 登陆用户
     * @return 部门数据权限
     */
    public DeptDataPermissionEntity getDeptDataPermission(AuthUser authUser) {

        return ROpt.ofNullable(roleService.getDataPermission()).assertSuccess(r -> new BusinessException(String.format("查询数据权限接口失败:%s", authUser.getUsername())))
                .peek().getData();
    }
}
